//Método base para máscara
function formataMascara(format, field) {
	var result = "";
	var maskIdx = format.length - 1;
	var error = false;
	var valor = field.value;
	var posFinal = false;

	if (field.setSelectionRange) {
		if (field.selectionStart == valor.length)
			posFinal = true;
	}

	valor = valor.replace(/[^0123456789]/g, '');

	for ( var valIdx = valor.length - 1; valIdx >= 0 && maskIdx >= 0; --maskIdx) {
		var chr = valor.charAt(valIdx);
		var chrMask = format.charAt(maskIdx);
		switch (chrMask) {
		case '#':
			if (!(/\d/.test(chr)))
				error = true;
			result = chr + result;
			--valIdx;
			break;
		case '@':
			result = chr + result;
			--valIdx;
			break;
		default:
			result = chrMask + result;
		}
	}

	field.value = result;
	field.style.color = error ? 'red' : '';

	if (posFinal) {
		field.selectionStart = result.length;
		field.selectionEnd = result.length;
	}

	return result;
}

function limitarTextArea(field, maxlimit) {
	
	if (field.value.length > maxlimit)
		field.value = field.value.substring(0, maxlimit);
	
}